<?php
/**
 * Abstraktny controller pre spolocnu cast hostingov
 * @author Tomas Srna
 * @package bakalarka
 */

abstract class HostingAbstractController extends Controller
{
	protected $resource = 'hosting';
	
	public function preDispatch()
	{
		if(array_key_exists(2, $this->args))
		{
			if($this->args[2] != 'data' &&
				$this->args[2] != 'go')
			{
				$this->resource = 'hosting:'.$this->args[2];
				$this->hosting = $this->args[2];
				
				$c = Selector::select('count(*) as c')->from(HostingModel::struct())
						->where('name = ?', $this->hosting)->fetch()->current()->c;
				if($c < 1)
					throw new Exception('L::errorObjectNotFound;'.
							json_encode(array('HostingModel('.$this->hosting.')')));
			}
		}
		else
			$this->hosting = NULL;
		if(property_exists($this, 'hosting'))
		{
			$this->plusmenu = new Menu(array(
				new Link(L::selected()->dashboard, 'hosting:'.$this->hosting, 
							'hosting/'.$this->hosting, 'index'),
				new Link(L::selected()->settings, 'hosting:'.$this->hosting, 
							'hosting/'.$this->hosting, 'settings'),
				new Link(L::selected()->ftp, 'hosting:'.$this->hosting, 
							'hosting/'.$this->hosting, 'ftp'),
				new Link(L::selected()->mysql, 'hosting:'.$this->hosting, 
							'hosting/'.$this->hosting, 'mysql'),
			));
			$this->plusmenu_title = sprintf(L::selected()->hosting_s, $this->hosting);
		}
		
		parent::preDispatch();
	}
}